package com.houseliker.adapter.calculate;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.houseliker.R;
import com.houseliker.adapter.BaseListAdapter;
import com.houseliker.model.Rate;

import java.util.List;

public class RateAdapter extends BaseListAdapter<Rate.RateValue> {

    public RateAdapter(Context context, List<Rate.RateValue> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (null == convertView) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_rate, null);
            holder.tv_content = (TextView) convertView.findViewById(R.id.tv_content);
            holder.tv_rate = (TextView) convertView.findViewById(R.id.tv_rate);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_content.setText(list.get(position).name);
//        if (0 == position) {
        holder.tv_rate.setText(list.get(position).value + "%");
        holder.tv_rate.setVisibility(View.VISIBLE);
//        } else {
//            holder.tv_rate.setVisibility(View.GONE);
//        }

        if (0 == position % 2) {
            convertView.setBackgroundColor(context.getResources().getColor(R.color.grayDB));
        } else {
            convertView.setBackgroundColor(context.getResources().getColor(R.color.white));
        }
        return convertView;
    }

    class ViewHolder {
        TextView tv_content, tv_rate;
    }
}
